"""
系统配置模型
"""
from sqlalchemy import Column, String, Boolean, Integer
from app.database import Base


class Config(Base):
    """系统配置表"""
    __tablename__ = "config"
    
    # 主键ID
    id = Column(Integer, primary_key=True, autoincrement=True)
    
    # 站点名称
    site_name = Column(String(255), nullable=True, default="MLPush")
    
    # 是否显示服务号绑定
    off_status = Column(Boolean, nullable=True, default=True, comment="是否显示服务号绑定")
    
    # 是否显示TG绑定
    tg_status = Column(Boolean, nullable=True, default=True, comment="是否显示tg绑定")
    
    # 实时汇率 (日元兑人民币)
    config_rate = Column(String(50), nullable=True, default="0.048", comment="实时汇率")
    
    def __repr__(self):
        return f"<Config(site_name='{self.site_name}', config_rate='{self.config_rate}')>"
    
    def get_rate_value(self) -> float:
        """获取汇率数值"""
        try:
            return float(self.config_rate) if self.config_rate else 0.048
        except (ValueError, TypeError):
            return 0.048
    
    def convert_jpy_to_cny(self, jpy_amount: float) -> float:
        """日元换算人民币"""
        rate = self.get_rate_value()
        return jpy_amount * rate